#include "ImageProcessor.h"

ImageProcessor::ImageProcessor() : isInitialized(false) {}

ImageProcessor::~ImageProcessor() {
    releaseCamera();
}

bool ImageProcessor::initializeCamera(int deviceId) {
    if (cap.open(deviceId)) {
        isInitialized = true;
        return true;
    }
    return false;
}

Mat ImageProcessor::captureFrame() {
    Mat frame;
    if (isInitialized) {
        cap >> frame;
    }
    return frame;
}

Mat ImageProcessor::preprocess(const Mat& frame) {
    Mat gray;
    cvtColor(frame, gray, COLOR_BGR2GRAY);
    equalizeHist(gray, gray);
    return gray;
}

void ImageProcessor::releaseCamera() {
    if (isInitialized) {
        cap.release();
        isInitialized = false;
    }
}